/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.qr_memeber;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.server.common.config.Global;
import com.server.common.persistence.Page;
import com.server.common.web.BaseController;
import com.server.common.utils.StringUtils;
import com.server.modules.sys.entity.qr_memeber.QrMember;
import com.server.modules.sys.service.qr_memeber.QrMemberService;

/**
 * 二维码客户Controller
 * @author 金
 * @version 2017-07-07
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/qr_memeber/qrMember")
public class QrMemberController extends BaseController {

	@Autowired
	private QrMemberService qrMemberService;
	
	@ModelAttribute
	public QrMember get(@RequestParam(required=false) String id) {
		QrMember entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = qrMemberService.get(id);
		}
		if (entity == null){
			entity = new QrMember();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:qr_memeber:qrMember:view")
	@RequestMapping(value = {"list", ""})
	public String list(QrMember qrMember, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<QrMember> page = qrMemberService.findPage(new Page<QrMember>(request, response), qrMember); 
		model.addAttribute("page", page);
		model.addAttribute("qrMember", qrMember);
		return "modules/sys/qr_memeber/qrMemberList";
	}

	@RequiresPermissions("sys:qr_memeber:qrMember:view")
	@RequestMapping(value = "form")
	public String form(QrMember qrMember, Model model) {
		model.addAttribute("qrMember", qrMember);
		return "modules/sys/qr_memeber/qrMemberForm";
	}

	@RequiresPermissions("sys:qr_memeber:qrMember:edit")
	@RequestMapping(value = "save")
	public String save(QrMember qrMember, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, qrMember)){
			return form(qrMember, model);
		}
		qrMemberService.save(qrMember);
		addMessage(redirectAttributes, "保存二维码客户成功");
		return "redirect:"+Global.getAdminPath()+"/sys/qr_memeber/qrMember/?repage";
	}
	
	@RequiresPermissions("sys:qr_memeber:qrMember:edit")
	@RequestMapping(value = "delete")
	public String delete(QrMember qrMember, RedirectAttributes redirectAttributes) {
		qrMemberService.delete(qrMember);
		addMessage(redirectAttributes, "删除二维码客户成功");
		return "redirect:"+Global.getAdminPath()+"/sys/qr_memeber/qrMember/?repage";
	}

}